package com.ruoyi.zhmk.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkCheck;
import com.ruoyi.zhmk.service.IZhmkCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员请假审核Controller
 * 
 * @author sxl
 * @date 2021-06-15
 */
@Controller
@RequestMapping("/zhmk/check")
public class ZhmkCheckController extends BaseController
{
    private String prefix = "zhmk/check";

    @Autowired
    private IZhmkCheckService zhmkCheckService;

    @RequiresPermissions("zhmk:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 首页展示待审核信息
     * @return
     */
    @RequiresPermissions("zhmk:check:view")
    @GetMapping("checkIndex")
    public String checkIndex()
    {
        return prefix + "/checkIndex";
    }

    /**
     * 查询人员请假审核列表
     */
    @RequiresPermissions("zhmk:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhmkCheck zhmkCheck)
    {
        startPage();
        List<ZhmkCheck> list = zhmkCheckService.selectZhmkCheckList(zhmkCheck);
        return getDataTable(list);
    }

    /**
     * 导出人员请假审核列表
     */
    @RequiresPermissions("zhmk:check:export")
    @Log(title = "人员请假审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhmkCheck zhmkCheck)
    {
        List<ZhmkCheck> list = zhmkCheckService.selectZhmkCheckList(zhmkCheck);
        ExcelUtil<ZhmkCheck> util = new ExcelUtil<ZhmkCheck>(ZhmkCheck.class);
        return util.exportExcel(list, "人员请假审核数据");
    }

    /**
     * 新增人员请假审核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存人员请假审核
     */
    @RequiresPermissions("zhmk:check:add")
    @Log(title = "人员请假审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhmkCheck zhmkCheck)
    {
        return toAjax(zhmkCheckService.insertZhmkCheck(zhmkCheck));
    }

    /**
     * 修改人员请假审核
     */
    @GetMapping("/edit/{checkId}")
    public String edit(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        ZhmkCheck zhmkCheck = zhmkCheckService.selectZhmkCheckById(checkId);
        mmap.put("zhmkCheck", zhmkCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员请假审核
     */
    @RequiresPermissions("zhmk:check:edit")
    @Log(title = "人员请假审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhmkCheck zhmkCheck)
    {
        return toAjax(zhmkCheckService.updateZhmkCheck(zhmkCheck));
    }

    /**
     * 删除人员请假审核
     */
    @RequiresPermissions("zhmk:check:remove")
    @Log(title = "人员请假审核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhmkCheckService.deleteZhmkCheckByIds(ids));
    }
}
